package com.yfl.tingyu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yfl.tingyu.pojo.Admin;
import com.yfl.tingyu.service.impl.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2020-05-26
 */
@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminServiceImpl adminService;

    /**
     * 登录模块
     * @param aname
     * @param apwd
     * @param m
     * @param session
     * @return
     */
    @RequestMapping("/login")
    public String login(String aname, String apwd, Model m, HttpSession session){

        QueryWrapper<Admin> qw = new QueryWrapper<>();
        qw.eq("aname",aname).eq("apwd",apwd);
        Admin admin = adminService.getOne(qw);

        if (admin==null){
                m.addAttribute("msg","您的账号或者密码错误");
            return "forward:/login.jsp";

        }
        //登录验证成功通过session共享用户数据
        session.setAttribute("SESSION_ADMIN",admin);
        return "index";
    }
}

